package com.smart.manager.work.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.ArcoTips;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.work.entities.body.RTaskKind;
import com.smart.manager.work.entities.models.TaskKind;
import com.smart.manager.work.repository.TaskKindRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * @author Administrator
 */

@Api(tags = "任务分类")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "work/customer/kind")
@RequiredArgsConstructor
public class TaskKindApi {

    private final TaskKindRepository taskKindRepository;



    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询任务分类")
    @SaCheckPermission("work:customer:kind:pageList")
    public AjaxResult<Page<TaskKind>> pageList(@Validated RTaskKind.SearchBody body) {
        Page<TaskKind> result = taskKindRepository.pageList(body);
        return AjaxResult.data(result);
    }


    @PostMapping(value = "add")
    @ApiOperation(value = "新增任务分类")
    @SaCheckPermission("work:customer:kind:add")
    public AjaxResult<String> add(@RequestBody @Validated RTaskKind.EditBody body) {
        taskKindRepository.add(body);
        return AjaxResult.success();
    }


    @PutMapping(value = "update/{id}")
    @ApiOperation(value = "修改任务分类")
    @SaCheckPermission("work:customer:kind:update")
    public AjaxResult<String> update(@PathVariable Long id, @RequestBody @Validated RTaskKind.EditBody body) {
        taskKindRepository.update(id, body);
        return AjaxResult.success();
    }


    @DeleteMapping(value = "delete")
    @ApiOperation(value = "删除任务分类")
    @SaCheckPermission("work:customer:kind:delete")
    public AjaxResult<Integer> delete(@RequestBody @NotEmpty(message = ArcoTips.PK_EMPTY) List<Long> ids) {
        int x = taskKindRepository.delByIds(ids);
        return AjaxResult.delSuccess(x);
    }

}
